# -*- mode: snippet -*-
# name: CART using rpart - template
# key: rpart.cart.tempalte
# key: cart.tempalte@rpart
# contributor : Shuguang Sun
# --
library(rpart)
library(rpart.plot)

${1:cart} <- rpart(${2:rsp} ~ ${3:factors},
               data = ${4:dt}, method = "class", control = rpart.control(cp = 0))

$1\$cptable

bestcp <- $1\$cptable[which.min($1\$cptable[,"xerror"]), "CP"]
${5:pt} <- prune($1, cp = bestcp)

rpart.plot($1)
rpart.plot($5)
